package com.douziit.meilianoa.controller;


import com.douziit.meilianoa.base.request.PageRequest;
import com.douziit.meilianoa.base.response.ResponseData;
import com.douziit.meilianoa.base.response.ResponseUtil;
import com.douziit.meilianoa.entity.ExecuteType;
import com.douziit.meilianoa.service.ExecuteTypeService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;

import java.util.List;

/**
 * 执行方式控制类
 */

@RestController
@RequestMapping("/executeType")
public class ExecuteTypeController {

    @Autowired
    private ExecuteTypeService executeTypeService;

    /**
     * 添加执行方式
     */
    @PostMapping("/addExecuteType")
    public ResponseData addExecuteType(@RequestBody ExecuteType executeType){
        executeTypeService.save(executeType);
        return ResponseUtil.jsonSuccess(0);
    }


    /**
     * 执行方式列表
     */
    @PostMapping("/listExecuteType")
    public ResponseData listExecuteType(){
        List<ExecuteType> list = executeTypeService.list();
        return ResponseUtil.jsonSuccess(list);
    }

    /**
     * 修改执行方式
     */
    @PostMapping("/changeExecuteType")
    public ResponseData changeExecuteType(@RequestBody ExecuteType executeType){

        executeTypeService.updateById(executeType);
        return ResponseUtil.jsonSuccess(0);
    }

    /**
     * 删除执行方式
     */
    @PostMapping("/deleteExecuteType")
    public ResponseData deleteExecuteType(@RequestBody PageRequest req){
        executeTypeService.removeById(req.getExecuteTypeId());
        return ResponseUtil.jsonSuccess(0);
    }
}
